from flask import Flask, request

import util.util as util

app = Flask(__name__)


@app.route('/', methods=['GET', 'POST'])
def hello():

    if 'GET' == request.method:
         return util.data_validata(request)

    if 'POST' == request.method:
        response_str = str(request.data, 'utf-8')
        res = util.xmlTodict(response_str)

       # print(res)
        return '''<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName> 
<CreateTime>12345678</CreateTime> 
<MsgType><![CDATA[text]]></MsgType> 
<Content><![CDATA[%s]]></Content> 
</xml>  ''' % (res['xml']['FromUserName'], res['xml']['ToUserName'], 'server   +    ' + res['xml']['Content'])
    return ''


# 假如有多个公众号
# select = input('''请选择你要使用的公众号：
# 1，xxx
# 2，yyy
# 3，zzz
# 4，aaa
# 5，bbb
# ''')


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=80)


